/**
 * 中间件
 *
 * Created by snowingsea on 2020/01/22.
 */
const license = require('./license');
const user = require('./user');
const environment = require('./environment');
const project = require('./project');
const projectVersion = require('./project-version');
const file = require('./file');
const func = require('./function');
const fileElement = require('./file-element');
const testCase = require('./test-case');
const task = require('./task');
const codeDefect = require('./code-defect');
const testCaseGroups = require('./test-case-groups');
const progressNotify = require('./progress-notify');
const codeInstrumentation = require('./code-instrumentation');

/**
 * 解析过滤器参数
 * @param req
 * @param res
 * @param next
 */
function splitFilter(req, res, next) {
  req.filter = {};
  req.filter.page = req.query.page ? parseInt(req.query.page, 10) : 1;
  req.filter.perPage = req.query.perPage ? parseInt(req.query.perPage, 10) : 20;
  req.filter.order = req.query.order ? req.query.order : 'asc';
  if (req.query.sortBy) req.filter.sortBy = req.query.sortBy;
  if (req.query.q) req.filter.q = req.query.q;
  next();
}

/**
 * Export model definition object.
 */
module.exports = {
  codeDefect,
  codeInstrumentation,
  environment,
  file,
  fileElement,
  function: func,
  license,
  project,
  projectVersion,
  testCase,
  testCaseGroups,
  task,
  user,
  splitFilter,
  progressNotify,
};
